<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String contextPath = (String) request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/js/jquery-easyui-1.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/css/rs.css">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath%>/js/jquery-easyui-1.3/themes/icon.css">
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/js/jquery-easyui-1.3/locale/easyui-lang-zh_CN.js"></script>
<script language="javascript">
var cur_pageSize=10;
var cur_pageNumber=1;

	$(function() {
		$('#dataTable').datagrid({
			title : '黑名单',
			height : 500,
			nowrap : true,
			autoRowHeight : false,
			striped : true,
			collapsible : false,
			url : '<%=contextPath%>/blackList/blackList.do?method=listData&pageNumber='+cur_pageNumber+'&pageSize='+cur_pageSize,
			remoteSort : false,
			idField : 'id',
							columns : [ [
									{
										field : 'ck',
										checkbox : true
									},
									{
										field : 'id',
										title : 'ID',
										width : 80,
										sortable : true
									},
									{
										field : 'status',
										title : '状态',
										width : 50,
										sortable : true,
										formatter : function(value, data, index) {
											if (data.status == 0) {
												return "解锁";
											} else {
												return "锁定";
											}
										}
									},
									{
										field : 'mobile_no',
										title : '用户手机号',
										width : 120,
										sortable : true
									},
									{
										field : 'reason',
										title : '黑名单原因',
										width : 220,
										sortable : true
									},
									{
										field : 'expire_time',
										title : '到期时间',
										width : 90,
										sortable : true,
										formatter : function(value, data, index) {
											return (data.expire_time.year + 1900)
													+ "-"
													+ (data.expire_time.month + 1)
													+ "-"
													+ (data.expire_time.date);
										}
									},
									{
										field : 'create_time',
										title : '创建时间',
										width : 90,
										sortable : true,
										formatter : function(value, data, index) {
											return (data.create_time.year + 1900)
													+ "-"
													+ (data.create_time.month + 1)
													+ "-"
													+ (data.create_time.date);
										}
									},
									{
										field : 'opt',
										title : '操作',
										width : 100,
										align : 'center',
										formatter : function(value, data, index) {
									 		return '<a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-reload\'" onClick="deleteSingle('+data.id+')">解禁</a>';
										}
									} ] ],

							pagination : true,
							rownumbers : true,

							toolbar : [ {
								id : 'btncut',
								text : '解禁	',
								iconCls : 'icon-cut',
								handler : function() {
									//$(function() {
										var rows = $('#dataTable').datagrid('getSelections');
										if (!rows || rows.length == 0) {
											$.messager.alert('提示',
													'请选择要解禁的记录!', 'info');
											return;
										}
										var parm;
										//循环给提交删除参数赋值
										$.each(rows, function(i, n) {
											if (i == 0) {
												parm = "id=" + n.id;
											} else {
												parm += "&id=" + n.id;
											}
										});
										$.messager.confirm(
														'提示',
														'是否解禁选中的记录?',
														function(r) {
															if (!r) {
																return;
															}
															//提交
															$.post('<%=contextPath%>/blackList/blackList.do?method=delete',
																	parm,
																	function(msg) {
																		//重新加载当前页
																		$('#dataTable').datagrid(msg.rows);
																	});
														});

									//});
								}
							} ]
						});
		var p = $('#dataTable').datagrid('getPager');
		$(p).pagination( {
			onRefresh : function() {
				var parm;
				parm='pageNumber=1&pageSize='+cur_pageSize;
				$.post('<%=contextPath%>/blackList/blackList.do?method=listData',
						parm,
						function(msg) {
							$('#dataTable').datagrid('clearSelections');
							//重新加载当前页
							$('#dataTable').datagrid(msg.rows);
						}
					);
			},
		    onSelectPage:function(pageNumber,pageSize){
				cur_pageSize=pageSize;
				cur_pageNumber=pageNumber;
				var parm;
				$('#dataTable').datagrid('clearSelections');
				parm='pageNumber='+pageNumber+'&pageSize='+pageSize;
				$.post('<%=contextPath%>/blackList/blackList.do?method=listData',
						parm,
						function(msg) {
							//重新加载当前页
							$('#dataTable').datagrid(msg.rows);
						}
					);
		    }
		});	
	});
	
	
	function deleteSingle(id){
		var parm;
		parm ='id='+id + '&pageNumber='+cur_pageNumber+'&pageSize='+cur_pageSize;
		$.messager.confirm(
				'提示',
				'确定删除?',
				function(r) {
					if (!r) {
						return;
					}
				$.post('<%=contextPath%>/blackList/blackList.do?method=delete',
				parm,
				function(msg) {
					 $('#dataTable').datagrid(msg.rows);
				});
		});
	}
</script>
<title>Insert title here</title>
</head>
<body>
<div id="dataTable"></div>
</body>